package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
@Controller
public class FileController {
    @RequestMapping("/fileUpload")
    public String fileupload(MultipartFile file,HttpServletRequest request) throws  IOException {
        String path = request.getServletContext().getRealPath("/");
        String upPath = "/static/upload";
        if (!file.isEmpty()) {
            String fileName = file.getOriginalFilename();
            String filepath = path+upPath + fileName;
            file.transferTo(new File(filepath));
            return "uploadSuccess";
        }
        return  "uploadFailure";
    }
}
